package cn.itcast.web.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import utils.Encrypt;

public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {

 /**
  * 密码比较
  */
 public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
  //获取登录的用户名和密码
  UsernamePasswordToken upToken = (UsernamePasswordToken) token;
  String email = upToken.getUsername();
  String password = new String(upToken.getPassword());
  //获取数据库密码
  String  dpPassword = (String) info.getCredentials();
  //对用户输入的密码加密
  password = Encrypt.md5(password, email);
  //比较两个密码
  return dpPassword.equals(password);
 }
}
